<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URL"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		// 设置请求的编码格式
		request.setCharacterEncoding("utf-8");
		// 设置响应的编码格式
		response.setCharacterEncoding("utf-8"); 
		
		String username = request.getParameter("username");
		if(username.equals("admin")){
			// 提示用户已存在
			request.setAttribute("message", "注册失败，该用户已存在！");
			request.getRequestDispatcher("userCreate.jsp").forward(request, response);
		}else{
			// 提示注册成功
			Cookie cookie = new Cookie("user",username);
			cookie.setMaxAge(60*60);
			response.addCookie(cookie);
			
			session.setAttribute("user", username);
			// 服务器主动清除长时间没有再次发出请求的session
			/* //(1)
			session.setMaxInactiveInterval(5); */
			//(2)
			response.sendRedirect("index.jsp");
		}
		String password = request.getParameter("password");
		out.print("用户名："+username + "<br/>");
		out.print("密码："+password + "<br/>");
		out.print("con_password:"+request.getParameter("con_password") + "<br/>");
		String email = request.getParameter("email");
	%>
	email:<%=email %>
</body>
</html>